package com.ts.code.creator.util;

import com.alibaba.fastjson.JSON;
import com.intellij.ide.util.PropertiesComponent;

public class CodePropertiesUtil {
    private static String KEY = "create-code-option";

    public static CodeProperties get() {
        PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
        String content = propertiesComponent.getValue(KEY);
        if (StringUtil.isNotBlank(content)) {
            try {
                return JSON.parseObject(content, CodeProperties.class);
            } catch (Exception ex) {
                propertiesComponent.setValue(KEY, null);
            }
        }
        return new CodeProperties();
    }

    public static void save(CodeProperties codeProperties) {
        if (codeProperties != null) {
            PropertiesComponent tempProperties = PropertiesComponent.getInstance();
            tempProperties.setValue(KEY, JSON.toJSONString(codeProperties));
        }
    }

}
